import json
from flask import Flask
from flask_sqlalchemy import SQLAlchemy


# 创建 db 实例
db = SQLAlchemy()
app = Flask(__name__)

def create_app():
    # 加载配置
    with open('config.json') as cf:
        config_data = json.load(cf)
    app.config.update(config_data)

    #registe
    from core.login import login_blueprint
    from core.personal import personal_blueprint
    from core.api import api_blueprint
    # from core.check import check_blueprint
    # from core.post import post_blueprint

    app.register_blueprint(login_blueprint)
    app.register_blueprint(personal_blueprint)
    app.register_blueprint(api_blueprint)
    # app.register_blueprint(check_blueprint)
    # app.register_blueprint(post_blueprint)

    db.init_app(app)

    return app


def create_db():
    with app.app_context():
        from models import User,Comment,Post,Prove,LikePost,LikeUser,LikeComment,Img
        db.create_all()

